/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.boundary;

import it.polimi.registration.business.security.control.PasswordEncrypter;
import it.polimi.registration.business.security.entity.Group;
import it.polimi.registration.business.security.entity.Users;
import javax.ejb.EJB;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.validation.ConstraintViolationException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import static org.hamcrest.CoreMatchers.*;

/**
 *
 * @author miglie
 */
@RunWith(Arquillian.class)
public class UsersManagerIT {
    

    @EJB
    UsersManager cut;
    
    @PersistenceContext
    EntityManager em;
    
//    @PersistenceContext
//    EntityManager em;

    @Deployment
    public static WebArchive createArchiveAndDeploy() {
        return ShrinkWrap.create(WebArchive.class)
                .addClass(UsersManager.class)
                .addClass(EntityManager.class)
                .addPackage(Users.class.getPackage())
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    }
   
    @Test
    public void newUserssShouldBeValid() {
        Users newUsers = new Users();
        newUsers.setEmail("invalidemail@mail.it");
        newUsers.setGroupName(Group.USERS);
        newUsers.setName("name");
        newUsers.setPassword("password");
        cut.save(newUsers);
        Users us=em.find(Users.class, "invalidemail@mail.it");
        assertEquals(us.getEmail(),newUsers.getEmail());
    }
}
